package ma.co.ba.BusinessApplications.presentation.controllers.listes;

import java.util.List;

import ma.co.ba.BusinessApplications.business.commons.CommonBusiness;
import ma.co.ba.BusinessApplications.business.tickets.TicketBusiness;
import ma.co.ba.BusinessApplications.business.utilisateurs.UtilisateurBusiness;
import ma.co.ba.BusinessApplications.model.Etat;
import ma.co.ba.BusinessApplications.model.Utilisateur;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/etats")
public class EtatController {
	@Autowired
	UtilisateurBusiness utilisateurBusiness;
	@Autowired
	TicketBusiness ticketBusiness;
	@Autowired
	CommonBusiness commonBusiness;

	@RequestMapping(method = RequestMethod.GET)
	public String listesPage(ModelMap model) {
		return "etats";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String processOnSubmit(@ModelAttribute("newEtat") Etat newEtat ,ModelMap model) {
		commonBusiness.saveEntity(newEtat);
		return "redirect:/etats";
	}


	@ModelAttribute("newEtat")
	public Etat getNewEtat() {
		return new Etat();
	}


	@ModelAttribute("etatsList")
	public List<Etat> getEtatsList() {
		return ticketBusiness.getAllEtats();
	}

	@ModelAttribute("utilisateurs")
	public List<Utilisateur> getUtilisateurs() {
		List<Utilisateur> utilisateurs = utilisateurBusiness
				.getAllConsultants();
		return utilisateurs;
	}
}
